package com.sc.mapper;

import java.io.IOException;
import java.util.List;

import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.splitWord.analysis.ToAnalysis;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import com.sc.bean.WordInfo;

/**
 * 
 * @Description 实现按词频排序
 * @author pengjun
 * @version v1.0
 * @date 2020年7月11日
 * 在map生成<"词名		词频", NullWritable>，因为map之后会根据key自动排序，所以写自定义排序和序列化类WordInfo作为key，自定义排序
 */
public class ZHWCSsortMapper extends Mapper<LongWritable, Text, WordInfo, NullWritable> {

	IntWritable intWritable = new IntWritable();
	Text text = new Text();
	WordInfo wi;

	
	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, WordInfo, NullWritable>.Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		String line = value.toString();
		String[] split = line.split("\t");
		text.set(split[0]);
		intWritable.set(Integer.parseInt(split[1]));
		wi = new WordInfo(text, intWritable);
		context.write(wi, NullWritable.get());
	}
}
